<template>
  <div class="app-container">
    <el-input
      placeholder="输入关键字进行过滤"
      v-model="filterText">
    </el-input>

    <el-tree
      class="filter-tree"
      :data="data"
      :props="defaultProps"
      :filter-node-method="filterNode"
      default-expand-all
      ref="tree">
    </el-tree>
<!--
    default-expand-all
    :default-checked-keys="['1']"
-->

  </div>
</template>
<script>
  import subjectApi from '@/api/subject'
  export default {
    watch: {
      filterText(val) {
        this.$refs.tree.filter(val);
      }
    },
    data() {
      return {
        filterText: '',
        data: [],
        defaultProps: {
          children: 'children',
          label: 'title'
        }
      };
    },
    created(){
      this.getAllSubjectList();
    },
    methods: {
      filterNode(value, data) {
        if (!value) return true;
        return data.title.toLowerCase().indexOf(value.toLowerCase()) !== -1;
      },
      getAllSubjectList(){
        subjectApi.getSubjects().then(response=> {
             this.data = response.data.list;
        })
      }
    }
  };
</script>
